<?php
/**
 * Wrapper for the Zend_Mail package
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @category VaselinEngine
 * @package Bel Classes
 * @license  New BSD License
 *
 */
class Bel_Mailer extends Zend_Mail {

    /**
     * Adapter
     *
     * @var string
     */
	protected $_adapter;
	/**
	 * Host
	 *
	 * @var string
	 */
	protected $_host;
	/**
	 * Strint
	 *
	 * @var string
	 */
	protected $_config;
	
	/**
	 * Public  constructor
	 *
	 * @param string $adapter
	 * @param string $charset
	 */
	function __construct($adapter = Bel_Mailer_Adapter::ADAPTER_MAIL,$charset='iso-8859-1') {
		$mailer_config = new Zend_Config_Ini( HOME_DIR . 'config/mailer.ini', 'mailer');
		$adapter = ($mailer_config->transport)?$mailer_config->transport:$adapter;
		
		$this->_getAdapter ($adapter);
		$this->setDefaultTransport($this->_adapter);
		
		$this->setFrom($mailer_config->from_email, $mailer_config->from);
		
		
		parent::__construct($charset);
	}
	
	/**
	 * Return adapter
	 *
	 * @param string $adapter
	 * @return object
	 */
	private function _getAdapter($adapter) {
		if (! isset ( $this->_adapter )) {
			$this->_adapter = Bel_Mailer_Adapter::factory ($adapter);
		}

		return $this->_adapter;
	}
}